﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{
    public enum eErrorCode
    {
        /// <summary>
        /// 0x00
        /// </summary>
        General,

        /// <summary>
        /// 0x01
        /// </summary>
        Unknown,

        /// <summary>
        /// 0x02
        /// </summary>
        NotFulfillable,

        /// <summary>
        /// 0x03
        /// </summary>
        NegativeConfirm,

        /// <summary>
        /// 0x04
        /// </summary>
        WrongSecurityCode,

        /// <summary>
        /// 0x10
        /// </summary>
        AddressOutOfRange,

        /// <summary>
        /// 0x18
        /// </summary>
        FunctionNotSupportedByAddress,

        /// <summary>
        /// 0x20
        /// </summary>
        DataOutOfRange,

        /// <summary>
        /// 0x80
        /// </summary>
        ChecksumError
    }

    public class UserData_11_Error : UserData_Device
    {
        #region private member variables

        private readonly eErrorCode _errorCode;
		
		#endregion private member variables

		#region constructor

        public UserData_11_Error(eErrorCode errorCode, byte device)
            : base(UserData.UserData11Error, device)
		{
            _errorCode = errorCode;
		}

		#endregion constructor

		#region getters

		public eErrorCode ErrorCode { get { return _errorCode; } }

		#endregion getters

		#region ToString, Equals, GetHashCode

		public override int GetHashCode()
		{
			int hashCode = base.GetHashCode();
            hashCode ^= (byte)_errorCode;

			return hashCode;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("(");
			stringBuilder.Append(ToStringProperties());
			stringBuilder.Append(")");

			return stringBuilder.ToString();
		}

		internal override string ToStringProperties()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(base.ToStringProperties());
			stringBuilder.Append(", ");

            stringBuilder.Append("ErrorCode='");
            stringBuilder.Append(ErrorCode);
			stringBuilder.Append("'");
			return stringBuilder.ToString();
		}

		public override bool Equals(object obj)
		{
			Type objType = obj.GetType();
			if (this.GetType() == objType)
			{
                UserData_11_Error userData2Compare = obj as UserData_11_Error;
                return EqualsProperties(userData2Compare);
			}

			return false;
		}

        internal bool EqualsProperties(UserData_11_Error userData2Compare)
		{
            if (base.EqualsProperties(userData2Compare))
			{
                return (ErrorCode == userData2Compare.ErrorCode);
			}

			return false;
		}		

		#endregion ToString, Equals, GetHashCode
    }
}
